﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ibuddylib {
    public enum GaugeType { 
        GoodBad,
        ColdWarm,
        Value
    };

    /// <summary>
    /// Class to turn an i-Buddy into a gauge, showing different levels of something
    /// </summary>
    public class BuddyGauge {
        private object[][] GAUGE_TYPE_COLORS = new object[][] {
            /* GaugeType.GoodBad */
            new object[] {
                HeadColor.Green, HeadColor.Yellow, HeadColor.Red
            },

            /* GaugeType.ColdWarm */
            new object[] {
                HeadColor.Blue, HeadColor.Cyan, HeadColor.Yellow, HeadColor.Red
            },

            /* GaugeType.Value */
            new object[] {
                HeadColor.Off, HeadColor.Blue, HeadColor.Purple, HeadColor.Green,
                HeadColor.Yellow, HeadColor.Cyan, HeadColor.White
            }
        };

        private BuddyAnimator animator;
        private int level;
        private GaugeType type;

        public BuddyGauge(IBuddy buddy) {
            animator = new BuddyAnimator(buddy);
            level = 0;
            type = GaugeType.GoodBad;
        }

        private void updateBuddy() {
            animator.Buddy.HeadColor = (HeadColor)GAUGE_TYPE_COLORS[(int)type][level];
        }

        public GaugeType Type {
            get {
                return type;
            }
            set {
                type = value;
                clipLevel();
                updateBuddy();
            }
        }

        private void clipLevel() {
            if (level > MaxLevel) level = MaxLevel;
            if (level < 0) level = 0;
        }

        public int Level {
            get {
                return level;
            }
            set {
                level = value;
                clipLevel();
                updateBuddy();
            }
        }

        public int MaxLevel {
            get {
                return GAUGE_TYPE_COLORS[(int)type].Length - 1;
            }
        }
    }
}